package cn.beatuty.makeup.module.system.controller.admin.statistics;

import cn.beatuty.makeup.framework.common.pojo.CommonResult;
import cn.beatuty.makeup.module.system.controller.admin.article.vo.ArticleSaveReqVO;
import cn.beatuty.makeup.module.system.dal.dataobject.orders.OrdersInfoDo;
import cn.beatuty.makeup.module.system.dal.mysql.article.ArticleMapper;
import cn.beatuty.makeup.module.system.dal.mysql.orders.OrdersMapper;
import cn.beatuty.makeup.module.system.dal.mysql.user.AdminUserMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.beatuty.makeup.framework.common.pojo.CommonResult.success;

/**
 * @author lfc
 */
@Tag(name = "管理后台 - 首页统计")
@RestController
@RequestMapping("/system/statistics")
@Validated
@Slf4j
public class StatisticsController {
    @Resource
    private OrdersMapper ordersMapper;

    @Resource
    private ArticleMapper articleMapper;

    @Resource
    private AdminUserMapper userMapper;

    @GetMapping("/query")
    @Operation(summary = "统计")
    public CommonResult<StatisticsVo> statistics() {
        //获取当前总交易额度
//        return success(articleService.createArticle(createReqVO));
        String totalPrice = ordersMapper.queryPriceTotal();
        String orderTotal = ordersMapper.queryOrderTotal();
        String articleTotal = articleMapper.queryArticleTotal();
        String queryUsers = userMapper.queryUsers();
        StatisticsVo statisticsVo = new StatisticsVo();
        statisticsVo.setTotalprice(totalPrice);
        statisticsVo.setTotalorder(Integer.valueOf(orderTotal));
        statisticsVo.setTotalarticles(Integer.valueOf(articleTotal));
        statisticsVo.setTotaluser(Integer.valueOf(queryUsers));
        List<OrdersInfoDo> ordersInfoDos = ordersMapper.queryOrdersInfo();
        statisticsVo.setOrdersInfoDos(ordersInfoDos);
        log.info("近七天情况：{}", ordersInfoDos);
        log.info("当前总用户为：{}", queryUsers);
        log.info("当前总文章为：{}", articleTotal);
        log.info("当前总交易订单为：{}", orderTotal);
        log.info("当前总交易额度为：{}", totalPrice);
        return CommonResult.success(statisticsVo);
    }
}
